package com.ctsi.offlinesupport.service;

import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * @author: zhangjw
 * @Date: 2018/11/1 10:03
 * @Description: 支撑环节事件记录任务状态
 */
@Component("supportTaskRecord")
@Primary
public class SupportTaskRecordService implements TaskListener {

    @Autowired
    private SupportTaskService supportTaskService;

    @Autowired
    private RuntimeService runtimeService;


    @Override
    public void notify(DelegateTask delegateTask) {
//        int isAuto = (int) delegateTask.getVariable(SupportFlowConstant.Variables.ISAUTO.name);
//        String eventName = delegateTask.getEventName();
//        if (eventName.equals("create") && isAuto==1) {
//            SupportTask stask = new SupportTask();
//            stask.setId(UUIDGenerator.getId());
//            stask.setBusinessKey((String) delegateTask.getVariable(SupportFlowConstant.Variables.BUSINESSKEY.name));
//            stask.setTaskStatus(-1);
//            stask.setProcessInstId(delegateTask.getProcessInstanceId());
//            stask.setSupportUserId((String) delegateTask.getVariable("supportUsers"));
//            stask.setTaskId(delegateTask.getId());
//            stask.setUserRoleType(1);
//            stask.setTaskBeginTime(System.currentTimeMillis());
//            this.supportTaskService.insertSupportTask(stask);
//        } else if (eventName.equals("complete")){
//            SupportTask update = new SupportTask();
//            SupportTask task = supportTaskService.findSupportTaskByUser(delegateTask.getId(), (String) delegateTask.getVariable("supportUsers"));
//            update.setId(task.getId());
//            update.setTaskStatus(2); //
//            update.setTaskEndTime(System.currentTimeMillis());
//            supportTaskService.updateSupportTaskByPKSelective(update);
//        }

    }
}
